In [ ]:
In [61]:
Collecting calmap
  Downloading https://files.pythonhosted.org/packages/60/7a/3340f348c4826fad190a265290ade1b7fbfbb311c84e27d82fb43e12d579/calmap-0.0.7-py2.py3-none-any.whl
Requirement already satisfied: numpy in /home/desire/anaconda3/lib/python3.7/site-packages (from calmap) (1.15.4)
Requirement already satisfied: pandas in /home/desire/anaconda3/lib/python3.7/site-packages (from calmap) (0.23.4)
Requirement already satisfied: matplotlib in /home/desire/anaconda3/lib/python3.7/site-packages (from calmap) (3.0.2)
Requirement already satisfied: python-dateutil>=2.5.0 in /home/desire/anaconda3/lib/python3.7/site-packages (from pandas->calmap) (2.7.5)
Requirement already satisfied: pytz>=2011k in /home/desire/anaconda3/lib/python3.7/site-packages (from pandas->calmap) (2018.7)
Requirement already satisfied: cycler>=0.10 in /home/desire/anaconda3/lib/python3.7/site-packages (from matplotlib->calmap) (0.10.0)
Requirement already satisfied: kiwisolver>=1.0.1 in /home/desire/anaconda3/lib/python3.7/site-packages (from matplotlib->calmap) (1.0.1)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /home/desire/anaconda3/lib/python3.7/site-packages (from matplotlib->calmap) (2.3.0)
Requirement already satisfied: six>=1.5 in /home/desire/anaconda3/lib/python3.7/site-packages (from python-dateutil>=2.5.0->pandas->calmap) (1.12.0)
Requirement already satisfied: setuptools in /home/desire/anaconda3/lib/python3.7/site-packages (from kiwisolver>=1.0.1->matplotlib->calmap) (40.6.3)
Installing collected packages: calmap
Successfully installed calmap-0.0.7
BokehJS 2.0.2 successfully loaded.

(Before moving on to the mapping, let's first try to map the covid19 data the same way!)

In [2]:
Out[2]:
SNo ObservationDate Province/State Country/Region Last Update Confirmed Deaths Recovered
0 1 01/22/2020 Anhui Mainland China 1/22/2020 17:00 1.0 0.0 0.0
1 2 01/22/2020 Beijing Mainland China 1/22/2020 17:00 14.0 0.0 0.0
2 3 01/22/2020 Chongqing Mainland China 1/22/2020 17:00 6.0 0.0 0.0
3 4 01/22/2020 Fujian Mainland China 1/22/2020 17:00 1.0 0.0 0.0
4 5 01/22/2020 Gansu Mainland China 1/22/2020 17:00 0.0 0.0 0.0
In [3]:
Out[3]:
(18008, 8)
In [4]:
Out[4]:
2
In [8]:
Out[8]:
SNo                  int64
ObservationDate     object
Province/State      object
Country/Region      object
Last Update         object
Confirmed          float64
Deaths             float64
Recovered          float64
dtype: object
In [7]:
Out[7]:
count     18008.000000
mean       2927.561528
std       14742.639567
min           0.000000
25%           9.000000
50%          97.000000
75%         653.000000
max      263460.000000
Name: Confirmed, dtype: float64
In [9]:
Out[9]:
count    18008.000000
mean       172.930475
std       1318.205640
min          0.000000
25%          0.000000
50%          1.000000
75%          8.000000
max      25549.000000
Name: Deaths, dtype: float64
In [10]:
Out[10]:
count     18008.000000
mean        734.016437
std        5437.543626
min           0.000000
25%           0.000000
50%           2.000000
75%          67.000000
max      103300.000000
Name: Recovered, dtype: float64

Let's splitt the dataset into three separate, and save into csv

In [22]:
Out[22]:
SNo ObservationDate Province/State Country/Region Last Update Confirmed
18005 18006 04/23/2020 Yukon Canada 2020-04-24 03:31:35 11.0
18006 18007 04/23/2020 Yunnan Mainland China 2020-04-24 03:31:35 184.0
18007 18008 04/23/2020 Zhejiang Mainland China 2020-04-24 03:31:35 1268.0
In [23]:
Out[23]:
SNo ObservationDate Province/State Country/Region Last Update Deaths
18005 18006 04/23/2020 Yukon Canada 2020-04-24 03:31:35 0.0
18006 18007 04/23/2020 Yunnan Mainland China 2020-04-24 03:31:35 2.0
18007 18008 04/23/2020 Zhejiang Mainland China 2020-04-24 03:31:35 1.0
In [25]:
Out[25]:
SNo ObservationDate Province/State Country/Region Last Update Recovered
18005 18006 04/23/2020 Yukon Canada 2020-04-24 03:31:35 0.0
18006 18007 04/23/2020 Yunnan Mainland China 2020-04-24 03:31:35 180.0
18007 18008 04/23/2020 Zhejiang Mainland China 2020-04-24 03:31:35 1256.0
In [26]:

Now, let's read these files and explore them¶

In [27]:
Out[27]:
SNo ObservationDate Province/State Country/Region Last Update Confirmed
0 1 01/22/2020 Anhui Mainland China 1/22/2020 17:00 1.0
1 2 01/22/2020 Beijing Mainland China 1/22/2020 17:00 14.0
2 3 01/22/2020 Chongqing Mainland China 1/22/2020 17:00 6.0
3 4 01/22/2020 Fujian Mainland China 1/22/2020 17:00 1.0
4 5 01/22/2020 Gansu Mainland China 1/22/2020 17:00 0.0
In [28]:
Out[28]:
SNo ObservationDate Province/State Country/Region Last Update Deaths
0 1 01/22/2020 Anhui Mainland China 1/22/2020 17:00 0.0
1 2 01/22/2020 Beijing Mainland China 1/22/2020 17:00 0.0
2 3 01/22/2020 Chongqing Mainland China 1/22/2020 17:00 0.0
3 4 01/22/2020 Fujian Mainland China 1/22/2020 17:00 0.0
4 5 01/22/2020 Gansu Mainland China 1/22/2020 17:00 0.0
In [29]:
Out[29]:
SNo ObservationDate Province/State Country/Region Last Update Recovered
0 1 01/22/2020 Anhui Mainland China 1/22/2020 17:00 0.0
1 2 01/22/2020 Beijing Mainland China 1/22/2020 17:00 0.0
2 3 01/22/2020 Chongqing Mainland China 1/22/2020 17:00 0.0
3 4 01/22/2020 Fujian Mainland China 1/22/2020 17:00 0.0
4 5 01/22/2020 Gansu Mainland China 1/22/2020 17:00 0.0

Some countries are included in the data despite having zero confirmed cases. So we remove these:

In [30]:
Out[30]:
SNo ObservationDate Province/State Country/Region Last Update Confirmed Deaths Recovered
0 1 01/22/2020 Anhui Mainland China 1/22/2020 17:00 1.0 0.0 0.0
1 2 01/22/2020 Beijing Mainland China 1/22/2020 17:00 14.0 0.0 0.0
2 3 01/22/2020 Chongqing Mainland China 1/22/2020 17:00 6.0 0.0 0.0
3 4 01/22/2020 Fujian Mainland China 1/22/2020 17:00 1.0 0.0 0.0
5 6 01/22/2020 Guangdong Mainland China 1/22/2020 17:00 26.0 0.0 0.0
In [31]:
Out[31]:
SNo ObservationDate Province/State Country/Region Last Update Confirmed
0 1 01/22/2020 Anhui Mainland China 1/22/2020 17:00 1.0
1 2 01/22/2020 Beijing Mainland China 1/22/2020 17:00 14.0
2 3 01/22/2020 Chongqing Mainland China 1/22/2020 17:00 6.0
3 4 01/22/2020 Fujian Mainland China 1/22/2020 17:00 1.0
5 6 01/22/2020 Guangdong Mainland China 1/22/2020 17:00 26.0
In [32]:
In [33]:
In [34]:
In [35]:

Some countries, such as China, are split into different provinces/states. Since we just want the total number of cases per country, we get the sum for each country at each date:

In [36]:
In [37]:
In [38]:
In [39]:

We are going to plot the log of the number of confirmed cases for each country, as there are a couple of countries, such as China and Italy, with a lot more cases compared to other countries.

In [40]:

We also need to convert the ObservationDate to unix time in nanoseconds:

In [41]:
In [42]:
In [46]:
In [47]:
In [48]:
In [49]:
Out[49]:
Country/Region ObservationDate SNo Confirmed date_sec
0 Azerbaijan 02/28/2020 2664 1.0 1582848000
1 ('St. Martin',) 03/10/2020 4675 2.0 1583798400
In [50]:
Out[50]:
Country/Region ObservationDate SNo Deaths date_sec
9790 occupied Palestinian territory 03/16/2020 6162 0.0 1584316800
9791 occupied Palestinian territory 03/17/2020 6438 0.0 1584403200
In [51]:
Out[51]:
Country/Region ObservationDate SNo Recovered date_sec
9790 occupied Palestinian territory 03/16/2020 6162 0.0 1584316800
9791 occupied Palestinian territory 03/17/2020 6438 0.0 1584403200

We can now select the columns needed for the map and discard the others:

In [52]:
Out[52]:
Country/Region date_sec log_Confirmed
9739 Zimbabwe 1587340800 1.397940
9740 Zimbabwe 1587427200 1.447158
9741 Zimbabwe 1587513600 1.447158
9742 Zimbabwe 1587600000 1.447158
9743 occupied Palestinian territory 1583798400 1.397940
In [53]:

Plot cases over time¶

In [63]:
1.58B1.581B1.582B1.583B1.584B1.585B1.586B1.587B00.5M1M1.5M2M2.5M
date_secConfirmed
In [65]:
1.58B1.581B1.582B1.583B1.584B1.585B1.586B1.587B050k100k150k200k
date_secDeaths
In [68]:
1.58B1.582B1.584B1.586B00.5M1M1.5M2M2.5M1.58B1.582B1.584B1.586B050k100k150k200k
Confirmed casesDeaths reported

Let's now get back to mapping data with matplotlib and then bokeh

read shape file¶

In [69]:

read data¶

In [70]:
                                                                                    url
name                                                                                   
Time series covid19 confirmed global  https://raw.githubusercontent.com/dnzengou/map...
Time series covid19 deaths global     https://raw.githubusercontent.com/dnzengou/map...
Time series covid19 recovered global  https://raw.githubusercontent.com/dnzengou/map...
In [ ]:

plot with matplotlib¶

In [71]:
In [ ]:

plot with bokeh¶

json data¶

In [72]:
In [81]:
BokehJS 2.0.2 successfully loaded.
WARNING:bokeh.io.export:There were browser warnings and/or errors that may have affected your export
WARNING:bokeh.io.export:file:///tmp/bokehm3du3zs0.html 998:1153 "[bokeh]"
Out[81]:
In [83]:
WARNING:param.Bokeh00023: Setting non-parameter attribute ax=AxesSubplot(0.0384921,0.178183;0.950794x0.643634) using a mechanism intended only for parameters
Out[83]:
1584208366
1584208366
In [ ]: